#include <stdio.h>
#include <memory.h>
int main()
{
    int d[4],b,c,n,i,j;
    char a[4];
    bool s[10000];
    while (scanf("%d",&n)!=EOF)
    {
        if (n==0)break;
        memset(s,true,sizeof(s));
        while (n--)
        {
            scanf("%s%d%d",a,&b,&c);
            for (d[0]=0;d[0]<10;d[0]++)
                for (d[1]=0;d[1]<10;d[1]++)
                    for (d[2]=0;d[2]<10;d[2]++)
                        for (d[3]=0;d[3]<10;d[3]++)
                        {
                            if (!s[d[0]*1000+d[1]*100+d[2]*10+d[3]])continue;
                            int t1=0,t2=0;
                            bool p[4],f[4];
                            memset(p,true,sizeof(p));
                            memset(f,true,sizeof(f));
                            for (i=0;i<=3;i++)
                            {
                                if (d[i]==a[i]-'0')
                                {
                                    t2++;t1++;
                                    f[i]=p[i]=false;
                                }
                            }
                            for (i=0;i<=3;i++)
                                for (j=0;j<=3;j++)
                                    if (p[i] && f[j] && d[j]==a[i]-'0')
                                    {
                                        t1++;
                                        p[i]=f[j]=false;
                                        break;
                                    }
                            if (t1!=b || t2!=c)s[d[0]*1000+d[1]*100+d[2]*10+d[3]]=false;
                        }
        }
        int t3=0,t4;
        for (i=0;i<=9999;i++)
            if (s[i])
            {
                t3++;
                t4=i;
            }
        if (t3==1)printf("%.4d\n",t4);
        else printf("Not sure\n");
    }
    return 0;
}
